#include <stdio.h>
#include <stdbool.h>
#include <assert.h>
#include <stdlib.h>
typedef int Qdatetype;
typedef struct QueueNode
{
	struct QueueNode* next;
	Qdatetype date;
}QNode;

typedef struct Queue
{
	QNode* head;
	QNode* tail;
	int size;
}Queue;




void QueueInit(Queue* pd)
{
	assert(pd);
	pd->head = NULL;
	pd->tail = NULL;
	pd->size = 0;
}
void Queuedestroy(Queue* pd)
{
	assert(pd);
	QNode* cur = pd->head;
	while (cur)
	{
		QNode* next = cur->next;
		free(cur);
		cur = next;
	}
	pd->head = pd->tail = NULL;
	pd->size = 0;
}
void Queuepush(Queue* pd, Qdatetype x)
{
	QNode* newnode = (QNode*)malloc(sizeof(QNode));
	assert(newnode);
	newnode->date = x;
	newnode->next = NULL;
	if (pd->head == NULL)
	{
		pd->head = pd->tail = newnode;
	}
	else
	{
		pd->tail->next = newnode;
		pd->tail = newnode;
	}
	pd->size++;
}
void Queuepop(Queue* pq)
{
	assert(pq);
	assert(pq->head != NULL);
	if (pq->head->next == NULL)
	{
		free(pq->head);
		pq->head = pq->tail = NULL;
	}
	else
	{
		QNode* next = pq->head->next;
		free(pq->head);
		pq->head = next;
	}

	pq->size--;
}
Qdatetype Queuesize(Queue* pd)
{
	assert(pd);
	return pd->size;
}
bool Queueempty(Queue* pd)
{
	assert(pd);
	return pd->size == 0;

}
Qdatetype Queuefront(Queue* pd)
{
	assert(pd);
	assert(!Queueempty(pd));
	return pd->head->date;
}
Qdatetype Queueback(Queue* pd)
{
	assert(pd);
	return pd->tail->date;
}
void test1(Queue* pd)
{
	Queuepush(pd, 1);
	Queuepush(pd, 2);
	Queuepush(pd, 1);
	Queuepush(pd, 2);
	Queuepush(pd, 1);
	Queuepush(pd, 2);
	
	while (!Queueempty(pd))
	{
		printf("%d", Queuefront(pd));
		printf("%d", Queuesize(pd));
		Queuepop(pd);
		printf("\n");

	}
	Queuedestroy(pd);
}

int main()
{
	Queue pd;
	QueueInit(&pd);
	test1(&pd);
	return 0;
}
